// 977. 有序数组的平方

/**
 * @param {number[]} nums
 * @return {number[]}
 */
var sortedSquares = function (nums) {
    let n = nums.length,
        left = 0,
        right = nums.length - 1,
        pos = n - 1,
        ret = [];
    while (left <= right) {
        if (nums[left] ** 2 > nums[right] ** 2) ret[pos] = nums[left++] ** 2;
        else ret[pos] = nums[right--] ** 2;
        pos--;
    }
    return ret;
};
